package com.cs.cssupplier.controller;

import com.cs.cssupplier.domain.CsAccess;
import com.cs.cssupplier.domain.CsAccessories;
import com.cs.cssupplier.mapper.CsAccessoriesMapper;
import com.cs.cssupplier.mapper.CsWinningResultsMapper;
import com.cs.cssupplier.service.CsAccessoriesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：lyj
 * @Package：com.cs.cssupplier.controller
 * @Project：RuoYi-Cloud-master
 * @name：CsAccessoriesController
 * @Date：2024/11/14 13:58
 * @Filename：CsAccessoriesController
 */
@RestController
@RequestMapping("/accessories")
public class CsAccessoriesController extends BaseController {
    @Resource
    private CsAccessoriesService csAccessoriesService;
    @Autowired
    private CsWinningResultsMapper mapper;
    /**
     * 根据id查询附件详细信息
     * @param fj_id
     * @return
     */
    @GetMapping(value = "cd/{fj_id}")
    public AjaxResult accessoriesId(@PathVariable("fj_id")Long fj_id){
        System.out.println(AjaxResult.success(csAccessoriesService.selectCsAccessoriesfjId(fj_id)));
        return AjaxResult.success(csAccessoriesService.selectCsAccessoriesfjId(fj_id));
    }

    /**
     * 查询附件所有信息
     * @param csAccessories
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(CsAccessories csAccessories){
        startPage();
        List<CsAccessories> list=csAccessoriesService.selectAccessoriesList(csAccessories);
        return getDataTable(list);
    }

    /**
     * 添加附件信息
     * @param csAccessories
     * @return
     */
    @PostMapping
    public AjaxResult insertAccessories(@RequestBody CsAccessories csAccessories){
        return toAjax(csAccessoriesService.addAccessories(csAccessories));
    }

    /**
     * 修改附件信息
     * @param csAccessories
     * @return
     */
    @PutMapping
    public AjaxResult updateAccessories(@RequestBody CsAccessories csAccessories){
        Long userid = SecurityUtils.getLoginUser().getUserid();
        Long sipplierByUserId = mapper.getSipplierByUserId(userid);//这才是供应商id
        csAccessories.setHid(sipplierByUserId);
        System.out.println(csAccessoriesService.updateAccessories(csAccessories));
        return toAjax(csAccessoriesService.updateAccessories(csAccessories));
    }

    /**
     * 批量修改附件信息
     * @param fj_id
     * @return
     */
    @DeleteMapping("/{fj_id}")
    public AjaxResult deleteAccessories(@PathVariable Long [] fj_id){
        return toAjax(csAccessoriesService.deleteListAccessories(fj_id));
    }
}
